#include<iostream>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
int a, b, c;
int dis[N];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> a >> b >> c;
		queue<int>q;
		while (q.size()) {
			q.pop();
		}
		q.push(a);
		q.push(b);
		q.push(c);
		int ans = -1;
		while (q.size()) {
			int a1 = q.front();
			q.pop();
			int a2 = q.front();
			q.pop();
			//cout << a1 << " " << a2 << endl;
			if (!a1 || !a2) {
				//cout << ans << endl;
				break;
			}
			ans++;
			q.push(a1 + a2);
			q.push(abs(a1 - a2));
			q.push(a1 * a2);
		}
	}
	return 0;
}